<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/4/7 0007
 * Time: 15:40
 */

namespace app\index\controller;


use think\Controller;

class User extends Controller
{
    public function login(){
        $data = db("user")->select();
        dump($data);
    }
    public function info(){
//        $member_id = input("member_id");
        if(request()->post()){
            $data = request()->param();
            $file = request()->file('');
            if(empty($file)){
                $image = request()->param('old_image');
            }else{
                $file = request()->file('image');
                $info=$file->move( './static/images');
                $filename=str_replace("\\","/",$info->getSaveName());
                $image = '/static/images/'.$filename;
            }
//            dump($data);die;
            if(empty($data['pen_name'])){
                $param = [
                    'head_img' => $image,
                    'nickname' => $data['nickname'],
                    'is_auto' => $data['is_auto'],
                    'mobile' => $data['mobile'],
                    'is_author' => $data['is_author'] ?? '',
                ];
            }else{
                $param = [
                    'head_img' => $image,
                    'nickname' => $data['nickname'],
                    'is_auto' => $data['is_auto'],
                    'mobile' => $data['mobile'],
                    'is_author' => $data['is_author'] ?? '',
                    'pen_name' => $data['pen_name'],
                ];
                db("book")->where('m_id',$data['id'])->update(['author' => $data['pen_name']]);
            }
            $res = db("member")->where('id',$data['id'])->update($param);
            if($res){
                $this->redirect('/');
            }else{
                $this->redirect('/index/user/info');
            }
        }
        $member_id = session('member_id');
        $member = db("member")->where('id',$member_id)->find();
        $footer = $this->footer();
//        dump($member);die;
        $this->assign([
            'member' => $member,
            'footer' => $footer
        ]);
        return view("info");
    }
    public function footer(){
        $data = db("web") ->cache(true,600)->find();
        return $data;
    }
}